package com.hdax.dm.controller;

import com.hdax.dm.dto.CommonResponse;
import com.hdax.dm.dto.DtoUtil;
import com.hdax.dm.dto.item.IndexNavDto;
import com.hdax.dm.service.IndexNavService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
public class IndexNavController {

    @Autowired
    private IndexNavService indexNavService;

    @PostMapping(path = "/nav")         //查询主页红商品
    public CommonResponse<List<IndexNavDto>> nav(){
        /*CommonResponse commonResponse = CommonResponse.builder()
                .msg("")
                .data(indexNavService.levelOne())
                .build();
        return commonResponse;*/
        return DtoUtil.returnSuccess("",indexNavService.levelOne());
    }

    @PostMapping(path = "/sortgoods")       //查询搜索页面商品分类
    public CommonResponse<List<IndexNavDto>> sortgoods(@RequestBody Map<String,Long> params){
        Long parent = params.get("parent");
        Long param = params.get("param");
        List<IndexNavDto> navDtos = new ArrayList<>();
        if(parent != null){
            navDtos = indexNavService.searchFenLei(parent);
        } else {
            navDtos = indexNavService.searchFenLei(param);
        }
        return DtoUtil.returnSuccess("",navDtos);
    }

}
